<!--交易中心的兼职工资页面-->
<div class="layui-card">
    <div class="layui-card-header">
        <h2 class="header-title">兼职工资</h2>
        <span class="layui-breadcrumb pull-right">
          <a href="#!console">首页</a>
          <a><cite>兼职工资</cite></a>
        </span>
    </div>
    <div class="layui-card-body">
        <div class="layui-form toolbar">
            搜索：
            <select id="concurrent-search-key">
                <option value="">-请选择-</option>
                <option value="username">兼职人</option>
                <option value="companyName">公司名</option>
                <option value="recommendedName">被推荐的人</option>
                <option value="job">职位</option>
            </select>&emsp;
            <input id="concurrent-search-value" class="layui-input search-input" type="text" placeholder="输入关键字"/>&emsp;
            <button id="concurrent-btn-search" class="layui-btn icon-btn"><i class="layui-icon">&#xe615;</i>搜索</button>
            <!--            <button id="user-btn-add" class="layui-btn icon-btn"><i class="layui-icon">&#xe654;</i>添加</button>-->
            <button id="concurrent-btn-export" class="layui-btn icon-btn"><i class="layui-icon">&#xe601;</i>导出</button>
        </div>

        <table class="layui-table" id="concurrent-table" lay-filter="concurrent-table"></table>
    </div>
</div>


<!-- 表格操作列 -->
<!--兼职工资没有修改-->
<!--    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edit">修改</a>-->
<script type="text/html" id="remittance-table-bar">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>

<!-- 表格状态列 -->
<!--<script type="text/html" id="concurrent-tpl-state">-->
<!--    <input type="checkbox" lay-filter="concurrent-tpl-state" value="{{d.id}}" lay-skin="switch" lay-text="热招中|关闭"-->
<!--           {{d.conduct==0?'checked':''}}/>-->
<!--</script>-->

<script>
    layui.use(['form', 'table', 'util', 'config', 'admin'], function () {
        var form = layui.form;
        var table = layui.table;
        var config = layui.config;
        var layer = layui.layer;
        var util = layui.util;
        var admin = layui.admin;

        //if( admin.hasPerm('user:add') ) {
        //   $('#btnAdd').hide();
        //}

        // 添加按钮绑定权限
        if(!admin.hasPerm('user:post/users/saveOrUpdate')) {
            $('#user-btn-add').hide();
        }

        // 导出按钮绑定权限
        if(!admin.hasPerm('user:post/users/saveOrUpdate')) {
            $('#user-btn-export').hide();
        }


        // 渲染表格
        table.render({
            elem: '#concurrent-table',
            // url: config.base_server + 'user_query.json',
            url: config.base_server + 'api-trade/concurrent/findAllConcurrent',
            method: 'GET',
            where: {
                access_token: config.getToken().access_token
            },
            page: true,
            //todo
            // 数据结果展示
            cols: [[
            {field: 'id', sort: true, title: '公司编号'},
            {field: 'companyname', sort: true, title: '公司名'},
            {field: 'remark', sort: true, title: '录用岗位'},
            {field: 'userId', sort: true, title: '兼职人员编号'},
            {field: 'nickName', sort: true, title: '兼职人员姓名'},
            {field: 'batchId',sort: true,title: '付款批次'},
            {field: 'prePay',sort: true,title: '预期金额'},
            {field: 'actuallyPay',sort: true,title: '实付金额'},
            {title: '操作',toolbar:"#remittance-table-bar"}
        ]]
        });
        // 添加按钮点击事件
        // $('#concurrent-btn-add').click(function () {
        //     showEditModel();
        // });

        // 工具条点击事件
        table.on('tool(concurrent-table)', function (obj) {
            var data = obj.data;
            var layEvent = obj.event;

            if (layEvent === 'edit') { // 修改
                showEditModel(data.batchId);
            } else if (layEvent === 'del') { // 重置密码
                doDelete(obj)
            }
        });
        // 删除
        var doDelete = function (obj) {
            layer.confirm('确定要删除吗？', function (i) {
                    obj.del();
                layer.msg('删除成功',{icon:1,time:800},function () {
                })
            });
        };
        //显示表单弹窗
        var showEditModel = function (data) {
            // 修改employment值是否录用
            // 修改payment值是否付款
            admin.putTempData('batchId', data);
            admin.popupCenter({
                title: "编辑工资记录",
                path: 'pages/trade/concurrent_form.html',
                finish: function () {
                    table.reload('concurrent-table', {});
                }
            });
        };

        // 搜索按钮点击事件
        $('#concurrent-btn-search').click(function () {
            var key = $('#concurrent-search-key').val();
            var value = $('#concurrent-search-value').val();
            table.reload('concurrent-table', {where: {searchKey: key, searchValue: value}});
        });


        // 导出
        $('#concurrent-btn-export').click(function () {
            var url = config.base_server + 'api-trade/concurrent/exportConcurrent?access_token='+config.getToken().access_token;
            var xhr = new XMLHttpRequest();
            xhr.open('POST', url, true);
            xhr.responseType = "blob";
            xhr.setRequestHeader("client_type", "DESKTOP_WEB");
            xhr.onload = function() {
                if (this.status == 200) {
                    var blob = this.response;
                    var objecturl = URL.createObjectURL(blob);
                    window.location.href = objecturl;
                }
            }
            xhr.send();
        });

    });
    function myJsonAjax(url, data, type, callback) {
        let token = JSON.parse(layui.data('easyweb').token).access_token
        $.ajax({
            url: 'http://127.0.0.1:9200/'+url,
            data: JSON.stringify(data),
            dataType:"json",
            type: type,
            contentType: "application/json",
            beforeSend: function (xhr) {
                xhr.setRequestHeader('Authorization', 'Bearer ' + token);
            },
            success: callback
        })
    }
</script>